FujairahZone = ZONE:New("FujairahZone")
ZoneCaptureCoalition_Fujairah = ZONE_CAPTURE_COALITION:New(FujairahZone,
SIDE.RED)

ZoneCaptureCoalition_Fujairah:__Guard(1)

ZoneCaptureCoalition_Fujairah:Start(1, 5)
local zoneflag_Fujairah = false
local airportname = "富查伊拉"

local function clientsController(switch)
    CLIENTS_Fujairah:ForEachClient(function ( client )
        local name = client.ClientName
        USERFLAG:New(name):Set(switch)
    end)
end

-- 开始防卫区域
function ZoneCaptureCoalition_Fujairah:OnEnterGuarded( From, Event, To )
    
    if From ~= To then
        local coalition = self:GetCoalition()
        if coalition == SIDE.RED then
            MESSAGE:New("敌人占领了" .. airportname .. "机场!", 10, "战局通报", false):ToAll()
            SOUND_RADIOTRANS:ToAll()
            
            clientsController(100)

            if REDBASE_Fujairah:GetFirstAliveGroup() == nil then
                REDBASE_Fujairah:Spawn()
            end -- 如果红方基地被摧毁了，则新建一个

            if Fujairah_ATTK then
                Fujairah_ATTK:SpawnScheduleStop()
            end -- 进攻富查伊拉的车队

        elseif coalition == SIDE.BLUE then
            MESSAGE:New("我们占领了" .. airportname .. "机场。请协助防御该机场。", 10, "战局通报", false):ToAll()
            clientsController(0)
            STAGE:Set(2)
            SOUND_AREASECURE:ToAll()
            
            zoneflag_Fujairah = true -- 更改富查伊拉机场flag

            if BLUEBASE_Fujairah:GetFirstAliveGroup() == nil then -- 生成蓝方基地检查
                BLUEBASE_Fujairah:Spawn()
            end
            
            if Fujairah_ATTK then
                Fujairah_ATTK:SpawnScheduleStart()
            end -- 进攻富查伊拉的车队
        end
    end
end

-- enter empty function
function ZoneCaptureCoalition_Fujairah:OnEnterEmpty()
    if zoneflag_Fujairah == false then -- 如果蓝方清空了机场

        MESSAGE:New("机场威胁已清除，地面部队正在接管" .. airportname .. "机场。", 10, "战局通报", false):ToAll()
        SOUND_JTFTRANS:ToAll()
        BLUEBASE_Fujairah:Spawn()
    else -- 如果红方清理了机场
        REDBASE_Fujairah:Spawn()
    end
end


function ZoneCaptureCoalition_Fujairah:OnEnterAttacked(From, Event, To)
    local coalition = self:GetCoalition()
    if coalition == SIDE.BLUE then
        MESSAGE:New(airportname .. "机场正在被敌方攻击！", 10, "战局通报", false):ToAll()
    else
        MESSAGE:New("我们正在攻击" .. airportname .. "机场！", 10, "战局通报", false):ToAll()
    end
    SOUND_JTFTRANS:ToAll()
end

